package main

import (
	"MaterialIdentification/svc"
	"github.com/gin-gonic/gin"
	"io"
	"net/http"
	"os"
)

func Downloadresult(context *gin.Context) {
	//i := Iddto{}
	//context.BindJSON(&i)
	//fmt.Println(i.Id)

	value := context.Query("id")

	l := Logs{}
	svc.Db.Find(&l, value)

	imagePath := "./result/" + l.Resultpicture

	file, err := os.Open(imagePath)
	if err != nil {
		context.String(http.StatusInternalServerError, "读文件异常: %s", err)
		return
	}
	defer file.Close()

	context.Header("Content-Type", "image/jpeg")

	//context.JSON(http.StatusOK, NewRespData("查询图片成功", file))
	_, err = io.Copy(context.Writer, file)
	if err != nil {
		context.String(http.StatusInternalServerError, "发送文件异常: %s", err)
		return
	}
}
